function handles = selectFile(handles)
% selectFile
% 
% Editing:
% gs may 2005
% -------------------------------------------------------

% change to the appropriate directory
try
    w = which('selectFile');
    i = strfind(w, '\');
    p = [w(1:i(end-1)) 'cellLists'];
    cd(p);
catch
    disp('selectFile: problem finding directory with cell lists');
end

% user selects a file
[filename, pathname] = uigetfile('*.mat', 'Pick a cell list file');
if isequal(filename,0)|isequal(pathname,0)
    return
end
fullname = fullfile(pathname, filename);
handles.analysis.mapAverager.cellLists.currentFile.data = load(fullname);

% filename -- store, and update in gui
handles.analysis.mapAverager.cellLists.currentFile.pname = pathname;
handles.analysis.mapAverager.cellLists.currentFile.fullname = fullname;
handles.analysis.mapAverager.cellLists.currentFile.fname = filename;
i = strfind(filename, '.');
set(handles.currentFile, 'String', filename(1:(i-1)));

% % reset list displays
% set(handles.groupList, 'Value', 1);
% set(handles.cellList, 'Value', 1);

% unpack
a = fieldnames(handles.analysis.mapAverager.cellLists.currentFile.data);
listsAndExpts = eval(['handles.analysis.mapAverager.cellLists.currentFile.data.' a{1}]);
handles.analysis.mapAverager.cellLists.currentFile.listsAndExpts = listsAndExpts;

% % populate the group list listbox 
% set(handles.groupList, 'String', listsAndExpts(:,1));

% populate the cell/expt listbox -- use list for group #1 by default
if ~isempty(listsAndExpts)
    set(handles.groupList, 'Value', 1);
    set(handles.groupList, 'String', listsAndExpts(:,1));
    set(handles.cellList, 'String', listsAndExpts{1,2});
    set(handles.cellList, 'Value', 1);
else
    set(handles.groupList, 'Value', 0);
    set(handles.groupList, 'String', {});
    set(handles.cellList, 'String', {});
    set(handles.cellList, 'Value', 0);
end

% if ~isempty(listsAndExpts)
%     set(handles.cellList, 'String', listsAndExpts{1,2});
% else
%     
% end
